package cn.com.nxt.txb;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

//import com.ksy.statlibrary.util.AuthUtils;
import com.netease.nimlib.sdk.NIMClient;
import com.netease.nimlib.sdk.auth.AuthService;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import cn.com.nxt.txb.education.util.Preferences;
import cn.com.nxt.txb.fragment.MineFragment;
import cn.com.nxt.txb.model.User;
import cn.com.nxt.txb.util.AppUtil;
import cn.com.nxt.txb.util.LogoutHelper;

@ContentView(R.layout.activity_user_info)
public class UserInfoActivity extends BaseActivity {
    public static final byte RESULT_NAME = 0x001;// 修改用户名成功时返回
    @ViewInject(R.id.tv_username)
    private TextView mUsernameTv;
    @ViewInject(R.id.tv_phone)
    private TextView mPhoneTv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);//注解绑定
        mUsernameTv.setText(AppUtil.mUser.getUsername());
        mPhoneTv.setText(AppUtil.mUser.getPhone());
    }

    @Event({R.id.ll_username, R.id.ll_modify_password, R.id.tv_logout})
    private void onViewClick(View v) {
        switch (v.getId()) {
            case R.id.ll_username:
                Intent intent = new Intent(UserInfoActivity.this,
                        ModifyUsernameActivity.class);
                startActivityForResult(intent, RESULT_NAME);
                break;
            case R.id.ll_modify_password:
                startActivity(new Intent(UserInfoActivity.this, ModifyPasswordActivity.class));
                break;
            case R.id.tv_logout:
                logout();
                break;
        }
    }

    /**
     * 注销
     */
    private void logout() {
//        if (SampleApplicationLike.mqttBinder != null) {
//            //unbindService(SampleApplicationLike.conn);
//        }
        MineFragment.isLogout=true;
        setResult(MineFragment.RESULT_LOGOUT, new Intent());
        finish();
    }

    @Override
    public void onActivityResult(int arg0, int arg1, Intent data) {
        super.onActivityResult(arg0, arg1, data);
//        if (data == null){
//            showToast("--null--");
//            return;}
        //showToast("用户名修改成功");
        if (arg0 == RESULT_NAME) {
            mUsernameTv.setText(AppUtil.mUser.getUsername());
            MineFragment.isUpdateUsername = true;
        }
    }
}
